from selenium import webdriver
import time

driver = webdriver.Firefox() #实例化浏览器对象
driver.implicitly_wait(5)
driver.get("http://192.168.2.155:8080/woniusales/")  #发送访问WoniuSales的请求
time.sleep(2)
assert driver.find_element_by_xpath("//div[1]/div[1]/div[1]/div[1]").is_displayed()  #断言是否进入蜗牛进销存登录页面

time.sleep(1)
driver.find_element_by_id('username').clear()        # 清空用户名
driver.find_element_by_id("username").send_keys("admin")   #输入用户名
time.sleep(1)
driver.find_element_by_id('password').clear()     # 清空密码
driver.find_element_by_id("password").send_keys("admin")  #输入密码
time.sleep(1)
driver.find_element_by_id("verifycode").clear()    #清空验证码
driver.find_element_by_id("verifycode").send_keys("0000")     #输入验证码
time.sleep(1)
driver.find_element_by_xpath("//html/body/div[4]/div/form/div[6]/button").click()  #点击登录
time.sleep(1)
try:
    driver.find_element_by_xpath("//*[@id='navbar']/ul[2]/li[2]/a").text=='注销'   #断言是否登录成功
    print("test001验证通过.")
except:
    print("test001验证失败.")